package com.chinaunicom.structure.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liry
 * @version 1.0
 * @date Created on 2022/7/29 15:45
 * Description:
 */
public class Composite implements Component {

    public List<Component> children = new ArrayList<>();
    private String name;

    public Composite(String name) {
        this.name = name;
    }

    public Composite add(Component c) {
        this.children.add(c);
        return this;
    }

    public void remove(Component c) {
        this.children.remove(c);
    }

    public List<Component> getChildren() {
        return this.children;
    }

    @Override
    public void execute() {
        System.out.println("composite ......" + this.name);
//        System.out.println("-----------------------------------------");
//        if (this.children != null && this.children.size() > 0){
//            for (Component child : this.children) {
//                child.execute();
//            }
//        }
    }
}
